/**
 * 
 */
package org.mhz.ootw.dataaccess;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.mhz.ootw.annotation.LogTimeTaken;
import org.mhz.ootw.entity.MenuItem;
import org.mhz.ootw.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Mahan
 *
 * Menu data access object
 */
@Repository(Constants.MENU_DAO)
@Transactional
public class MenuDAO
{
    private static final Logger LOGGER = LoggerFactory.getLogger(MenuDAO.class);    

    @Resource(name = Constants.SESSION_FACTORY)
    private SessionFactory mSessionFactory;
    
    /**
     * Retrieves all menu items
     * 
     * @return a list of menu items
     */
    @LogTimeTaken
    public List<MenuItem> getAll() 
    {
        // Retrieve session from Hibernate
        final Session session = mSessionFactory.getCurrentSession();
      
         // Create a Hibernate query (HQL)
        final Query query = session.createQuery("FROM  MenuItem");
        
        // Retrieve all
        return  query.list();
    }    
}
